package com.sc.nft.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.sc.nft.dao.UserRelevanceDao;
import com.sc.nft.entity.ApplicationRequirement;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.UserRelevance;
import com.sc.nft.entity.vo.ApplicationRequirementFactoryVO;
import com.sc.nft.enums.ApplicationRequirementEnum;
import com.sc.nft.service.ApplicationRequirementFactoryService;
import com.sc.nft.util.DecideUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
 * 直推社区网点
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class DirectPushCommunityServiceImpl implements ApplicationRequirementFactoryService {
    private final UserRelevanceDao userRelevanceDao;
    @Override
    public ApplicationRequirementFactoryVO applicationRequirement(UserInfo userInfo, ApplicationRequirement applicationRequirement, Integer type) {
        // 获取这个用户下属的直推社区网点
        Integer directThrustCommunityNetworkCount = userRelevanceDao.directThrustCommunityNetworkCount(userInfo.getId());
        ApplicationRequirementFactoryVO applicationRequirementFactoryVO = new ApplicationRequirementFactoryVO();
        applicationRequirementFactoryVO.setKey(StrUtil.format("{}{}{}", applicationRequirement.getType().getDescription(), applicationRequirement.getJudgingCriteria(), Convert.toInt(applicationRequirement.getValue())));
        applicationRequirementFactoryVO.setAskForValue(applicationRequirement.getValue());
        applicationRequirementFactoryVO.setApplicationRequirementEnum(ApplicationRequirementEnum.IMMEDIATE_ACCOUNT);
        applicationRequirementFactoryVO.setPracticalValue(directThrustCommunityNetworkCount);
        applicationRequirementFactoryVO.setPracticalValueStr(directThrustCommunityNetworkCount);
        // 根据compoundMode字段中的 > < >= <= = 五中 来判定是否满足条件
        applicationRequirementFactoryVO.setSatisfy(DecideUtil.conditionalDecision(directThrustCommunityNetworkCount, Convert.toInt(applicationRequirement.getValue()), applicationRequirement.getJudgingCriteria()));
        return applicationRequirementFactoryVO;
    }
    @Override
    public Integer code() {
        return ApplicationRequirementEnum.DIRECT_PUSH_COMMUNITY.getCode();
    }
}
